<!DOCTYPE html>
<html>
<head>
    <title>{{view_name}}编辑</title>
    {% raw %} {% include '../common/header.html' %} {% endraw %}
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item layui-hide">
                    <label class="layui-form-label">编号</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{'{{'}} model['id'] {{'}}'}}" name="id" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>

                {% for column in column_list if column['field_name'] not in ["id", "create_at", "update_at"] -%}
                {% if column['field_type'] == "textarea" %}
                <div class="layui-form-item layui-form-text">
                    <label class="layui-form-label">{{column['field_comment']}}</label>
                    <div class="layui-input-block">
                        <textarea placeholder="请输入" name="{{column['field_name']}}" class="layui-textarea">{{'{{'}} model['{{column['field_name']}}'] {{'}}'}}</textarea>
                    </div>
                </div>
                {% else %}
                <div class="layui-form-item">
                    <label class="layui-form-label">{{column['field_comment']}}</label>
                    <div class="layui-input-block">
                        <input type="text" name="{{column['field_name']}}" autocomplete="off" placeholder="请输入"
                               class="layui-input" value="{{'{{'}} model['{{column['field_name']}}'] {{'}}'}}">
                    </div>
                </div>
                {% endif %}
                {% endfor %}
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="{{view_name}}-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% raw %} {% include '../common/footer.html' %} {% endraw %}
<script>
  layui.use(['form', 'jquery'], function () {
    let form = layui.form
    let $ = layui.jquery

    let MODULE_PATH = '/admin/{{view_name}}/'

    form.on('submit({{view_name}}-update)', function (data) {
      $.ajax({
        url: MODULE_PATH+'update',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'post',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
              parent.layui.table.reload('{{view_name}}-table')
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
<script>
</script>
</body>
</html>